<?php



namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

/**
 * 评论点赞
 */
class CommentLike extends Model
{
    protected $table = 'moment_comment_like';

    protected $fillable = [
        "user_id", "moment_id", "comment_id",  "flag"
    ];

    /**
     * 添加点赞记录
     */
    static function addLike($userId = 0, $commentId = 0, $flag = 1, $momentId = 0)
    {
        $ret = self::updateOrCreate([
            'user_id' => $userId,
            'comment_id' => $commentId,
        ], [
            'user_id' => $userId,
            'comment_id' => $commentId,
            'moment_id' => $momentId,
            'flag' => $flag
        ]);
        return $ret ? 1 : 0;
    }
}
